#include"RingQueue.hpp"
#include<pthread.h>
#include<ctime>
#include<unistd.h>

void *Consumer(void *args)
{
    RingQueue<int> *rq=static_cast<RingQueue<int>*>(args);
    while(true)
    {
        sleep(1);
        int data;
        rq->Pop(&data);
        std::cout<<"Consumer get data :"<<data<<" done"<<std::endl;
    }
}
void *Productor(void *args)
{
    RingQueue<int> *rq=static_cast<RingQueue<int>*>(args);
    while(true)
    {
        
        int data=rand()%10+1;
        rq->Push(data);
        std::cout<<"Productor put data :"<<data<<" done"<<std::endl;
    }
}

int main()
{
    srand(time(nullptr));
    RingQueue<int> *rq=new RingQueue<int>(5);
    pthread_t c1,c2,p1,p2,p3;
    pthread_create(&c1,nullptr,Consumer,rq);
    pthread_create(&c2,nullptr,Consumer,rq);
    pthread_create(&p1,nullptr,Productor,rq);
    pthread_create(&p2,nullptr,Productor,rq);
    pthread_create(&p3,nullptr,Productor,rq);

    pthread_join(c1,nullptr);
    pthread_join(c2,nullptr);
    pthread_join(p1,nullptr);
    pthread_join(p2,nullptr);
    pthread_join(p3,nullptr);
    return 0;
}